package cn.iocoder.yudao.module.system.repository.mybatis.dao.permission;

import cn.iocoder.yudao.core.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.core.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.system.repository.mybatis.domain.permission.Menu;
import cn.iocoder.yudao.module.system.vo.permission.menu.MenuListReqVO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

@Mapper
public interface MenuMapper extends BaseMapperX<Menu> {

    default Menu selectByParentIdAndName(Long parentId, String name) {
        return selectOne(Menu::getParentId, parentId, Menu::getName, name);
    }

    default Long selectCountByParentId(Long parentId) {
        return selectCount(Menu::getParentId, parentId);
    }

    default List<Menu> selectList(MenuListReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<Menu>()
                .likeIfPresent(Menu::getName, reqVO.getName())
                .eqIfPresent(Menu::getStatus, reqVO.getStatus()));
    }

    default List<Menu> selectListByPermission(String permission) {
        return selectList(Menu::getPermission, permission);
    }

}
